package com.example.github.enum_use;

/**
 * Java 枚举是一个特殊的类，一般表示一组常量，比如一年的 4 个季节，一个年的 12 个月份，一个星期的 7 天，方向有东南西北等。
 * Java 枚举类使用 enum 关键字来定义，各个常量使用逗号 , 来分割。
 * 例如定义一个颜色的枚举类。
 */
enum WeekDay {
    //类外部定义枚举
    WEEK_1("01", "星期一"), WEEK_2("02", "星期二"), WEEK_3("03", "星期三"),
    WEEK_4("04", "星期四"), WEEK_5("05", "星期五"), WEEK_6("06", "星期六"),
    WEEK_7("07", "星期日");

    private String code;
    private String desc;

    WeekDay(String code, String desc){
        this.code = code;
        this.desc = desc;
    }

    public static WeekDay getWeekDay(String code){
        for (WeekDay weekDay : WeekDay.values()){
            if (weekDay.getCode().equals(code)) {
                return weekDay;
            }
        }
        return null;
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
public class TestEnum {
    enum Color{
        // 类内部定义枚举
        RED, BLUE, YELLOW
    }
    public static void main(String[] args) {
        Color red = Color.RED;
        System.out.println(red); // RED
        /*
        WeekDay weekDay = WeekDay.valueOf("WEEK_2");
        switch (weekDay){
            case WEEK_1:
                System.out.println("星期一");
                break;
            case WEEK_2:
                System.out.println("星期二");
                break;
            case WEEK_3:
                System.out.println("星期三");
                break;
            case WEEK_4:
                System.out.println("星期四");
                break;
            case WEEK_5:
                System.out.println("星期五");
                break;
            case WEEK_6:
                System.out.println("星期六");
                break;
            default:
                System.out.println("星期天");
        }
         */
        System.out.println("今天是： " + WeekDay.getWeekDay("01").getDesc());
    }
}
